<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增产品项目组')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-group-add">
            <input id="treeId" name="parentId" type="hidden" th:value="${group.groupId}"   />
            <input id="projectCode"  name="projectCode" type="hidden" th:value="${group.projectCode}"   />
            <div class="form-group">
                <label class="col-sm-3 control-label">上级部门：</label>
                <div class="col-sm-8">
                    <div class="input-group">
                        <input class="form-control" type="text" onclick="selectGroupTree()" id="treeName" readonly="true" th:value="${group.groupName}">
                        <span class="input-group-addon"><i class="fa fa-search"></i></span>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">项目组名称：</label>
                <div class="col-sm-8">
                    <input name="groupName" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">项目id：</label>
                <div class="col-sm-8">
                    <input name="projectId" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">显示顺序：</label>
                <div class="col-sm-8">
                    <input name="orderNum" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">负责人：</label>
                <div class="col-sm-8">
                    <input name="leader" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">联系电话：</label>
                <div class="col-sm-8">
                    <input name="phone" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">邮箱：</label>
                <div class="col-sm-8">
                    <input name="email" class="form-control" type="text">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门状态：</label>
                <div class="col-sm-8">
                    <div class="radio-box" th:each="dict : ${@dict.getType('sys_normal_disable')}">
                        <input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
                        <label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
                    </div>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">删除标志：</label>
                <div class="col-sm-8">
                    <input name="delFlag" class="form-control" type="text">
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <script type="text/javascript">
        var prefix = ctx + "system/group"
        $("#form-group-add").validate({
            onkeyup: false,
            rules:{
                deptName:{
                    remote: {
                        url: prefix + "/checkGroupNameUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "parentId": function() {
                                return $("input[name='parentId']").val();
                            },
                            "projectId": function() {
                                return $("input[name='projectId']").val();
                            },
                            "groupName" : function() {
                                return $.common.trim($("#groupName").val());
                            }
                        },
                        dataFilter: function(data, type) {
                            return $.validate.unique(data);
                        }
                    }
                },
                orderNum:{
                    digits:true
                },
                email:{
                    email:true,
                },
                phone:{
                    isPhone:true,
                },
            },
            messages: {
                "deptName": {
                    remote: "组已经存在"
                }
            },
            focusCleanup: true
        });



        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-group-add').serialize());
            }
        }


        /*项目组管理-新增-选择父组织机构树*/
        function selectGroupTree() {
            var options = {
                title: '项目组选择',
                width: "380",
                url: prefix + "/selectGroupTree/" + $("#projectCode").val(),
                callBack: doGroupSubmit
            };
            $.modal.openOptions(options);
        }

        function doGroupSubmit(index, layero){
            var body = layer.getChildFrame('body', index);
            console.log(body.find('#treeId').val());
            console.log(body.find('#treeName').val());
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }

    </script>
</body>
</html>